<!DOCTYPE html>
<html lang="zh-CN">

<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
	<meta name="description" content="">
	<meta name="author" content="">
	<title>班级说说</title>

	<!-- Bootstrap core CSS -->
	<link href="css/bootstrap.min.css" rel="stylesheet">

</head>

<body>

	<% include header.ejs %>
		<!-- Main jumbotron for a primary marketing message or call to action -->
		<div class="jumbotron">

			<div class="container">
				<% if(!login){ %>
					<p>
						<a href="/login">欢迎！</a>
					</p>
					<p>班级说说是我们交流的园地，请先注册</p>
					<%}else{%>
						<div class="row">
							<div class="col-lg-1">
								<a href="/setavatar">
									<img src="/avatar/<%= avatar %>" width="50" alt="">
								</a>
							</div>
							<div class="col-lg-6 col-offset-1">
								<p>欢迎，
									<%= username %>
								</p>
								<textarea name="" id="shuoshuo" cols="80" rows="5"></textarea>
								<button class="btn btn-success" id="button">发表说说</button>
							</div>
						</div>
						<% } %>
			</div>


		</div>

		<div class="container">
			<!-- Example row of columns -->
			<div class="row">
				<% if(shuoshuo.length!=0){ %>
					<% for(var i=0;i<shuoshuo.length;i++){ %>
					<div class="col-md-4">
						<h2><%= shuoshuo[i].username%></h2>
						<p><%= shuoshuo[i].content%></p>
						<p>
							<a class="btn btn-default" href="#" role="button">View details &raquo;</a>
						</p>
					</div>
					<% }%>
				<% } %>
			</div>

			<hr>

			<footer>
				<p>&copy; 2016 Company, Inc.</p>
			</footer>
		</div>

		<!-- Bootstrap core JavaScript
    ================================================== -->
		<!-- Placed at the end of the document so the pages load faster -->
		<script src="js/jquery-1.9.1.js"></script>
		<script src="js/bootstrap.min.js"></script>
		<script>
			$('#button').click(() => {
				if($('#shuoshuo').val()==''){
					alert('请输入内容')
					return;
				}
				$.post('/toshuoshuo', {
					content: $('#shuoshuo').val()
				}, (res) => {
					if (res == -3) {
						alert('网络错误');
						return;
					};
					if (res == 1) {
						location.href='/';
						return;
					};
				})
			})
		</script>
</body>

</html>